package com.talent.service.iot.mqtt.codec.encoder;

import com.talent.service.iot.mqtt.model.fix.TlMqttFixedHead;
import com.talent.service.iot.mqtt.model.response.TlMqttHeartBeat;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @ClassName：TlConnackDecoder
 * @Author: hszhou
 * @Date: 2024/11/30 15:35
 * @Description: puback的编码
 */
@ChannelHandler.Sharable
@Component
public class TlMqttHeaderBeatEncoder extends MessageToByteEncoder<TlMqttHeartBeat> {

    private static final  Logger logger = LoggerFactory.getLogger(TlMqttHeaderBeatEncoder.class);

    @Override
    protected void encode(ChannelHandlerContext ctx, TlMqttHeartBeat res, ByteBuf out) throws Exception {
        logger.debug("in 【PINGRES】 encode");
        TlMqttFixedHead fixedHead = res.getFixedHead();
        int messageType= fixedHead.getMessageType().value()<<4;
        out.writeByte(messageType);
        out.writeByte(0);

    }

}
